package service.impl;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import config.direct.DirectExchangeConfig;
import config.direct.DirectRoutingKeyEnum;
import po.Mail;
import service.Publisher;

@Service("publisher")
public class PublisherImpl implements Publisher {
	@Autowired
	RabbitTemplate rabbitTemplate;

	@Override
	public void sendDirectMail(Mail mail, DirectRoutingKeyEnum routingkey) {
		rabbitTemplate.convertAndSend(DirectExchangeConfig.EXCHANGE_NAME, routingkey.name(), mail);
	}
	
	@Override
	public void publishMail(Mail mail) {
		rabbitTemplate.convertAndSend("fanout", "", mail);
	}


	@Override
	public void sendtopicMail(Mail mail, String routingkey) {
		rabbitTemplate.convertAndSend("mytopic", routingkey, mail);
	}

}
